package com.zkingsoft.actions.admin;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.config.Dictionary;
import com.zkingsoft.model.Btn;
import com.zkingsoft.model.ShowElementCate;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.BtnService;
import com.zkingsoft.services.ShowElementCateService;

/**
 * @project MatrixCms
 * @package FunctionController
 * @class com.zkingsoft.actions.admin.FunctionController
 * @author Matrix-J E-mail:<935090232@qq.com>
 * @date 2016年4月21日10:31
 * @description 功能管理
 */
@Controller
@RequestMapping(value = "/admin/articleCate")
public class ArticleCateController extends BaseController {


	@Resource
	private ShowElementCateService currentService;

	@Resource
	private BtnService btnService;

	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all( HttpServletRequest request) {
		ShowElementCate showElementCateQuery=new ShowElementCate();
		showElementCateQuery.setCompanyId(getMe(request).getCompanyId());
		showElementCateQuery.setType(Dictionary.ELEMENT_TYPE_ARTICLE);
		return findByModel(currentService, showElementCateQuery);
	}

	
	/**
	 * findByModel
	 * 
	 * @param showElementCateQuery
	 * @return
	 */
	@RequestMapping(value = "/findByModel")
	public @ResponseBody AjaxResult findByModel(ShowElementCate showElementCateQuery, HttpServletRequest request) {
		showElementCateQuery.setCompanyId(getMe(request).getCompanyId());
		showElementCateQuery.setType(Dictionary.ELEMENT_TYPE_ARTICLE);
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功",
				currentService.findByModel(showElementCateQuery), 0, 0);
	}

	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(Long id) {
		ShowElementCate showElementCate = super.findById(currentService, id);
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, Arrays.asList(showElementCate), 0, 0);
	}

	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(ShowElementCate showElementCateQuery, HttpServletRequest request) {
		if (showElementCateQuery.getId() != null) {
			return modify(currentService, showElementCateQuery, "类型");
		} else {
			showElementCateQuery.setCompanyId(getMe(request).getCompanyId());
			showElementCateQuery.setType(Dictionary.ELEMENT_TYPE_ARTICLE);
			return add(currentService, showElementCateQuery, "类型");
		}
	}

	
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}
	
	
	@RequestMapping(value = "/editForm")
	public String editForm(Long id, HttpServletRequest request) {
		ShowElementCate showElementCate;
		if (id != null) {
			showElementCate = currentService.findById(id);
			request.setAttribute("obj", showElementCate);
		}
		List<Btn> btnList = btnService.findByModel(null);
		request.setAttribute("btnList", btnList);
		return "admin/articleCate-form";
	}
	
}